<template>
  <div class="classAssociate">
    <el-breadcrumb separator="/" class="breadcrumb-bottom">
      <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item>毕业设计</el-breadcrumb-item>
      <el-breadcrumb-item>教研室分配学生</el-breadcrumb-item>
    </el-breadcrumb>
    <el-row :gutter="20" class="mb-12">
      <el-col :span="5">
        <div class="">
          <el-select v-model="AssociateForm.majorID" placeholder="请选择专业" class="full-line">
            <el-option v-for="item in majorData" :label="item.majorName" :value="item.majorID"></el-option>
          </el-select>
        </div>
      </el-col>
      <el-col :span="5">
        <div class="">
          <el-date-picker
            @change="changeAcademicYear"
            v-model="AssociateForm.academicYear"
            align="right"
            type="year"
            class="max-width"
            placeholder="请选择学年">
          </el-date-picker>
        </div>
      </el-col>
      <el-col :span="2">
        <div>
          <el-button type="primary" @click="search">立即搜索</el-button>
        </div>
      </el-col>
    </el-row>
    <el-table
      :data="associateTable"
      style="width: 100%"
      max-height="250">
      <el-table-column
        prop="graduateTitle"
        label="课题名称"
        min-width="120">
      </el-table-column>
      <el-table-column
        prop="titleSource"
        label="课题来源"
        min-width="120">
      </el-table-column>
      <el-table-column
        prop="num"
        label="要求人数"
        min-width="100">
      </el-table-column>
      <el-table-column
        prop="itemCategoryName"
        label="项目类别名称"
        min-width="120">
      </el-table-column>
      <el-table-column
        prop="itemCategoryID"
        label="项目类别编号"
        min-width="120">
      </el-table-column>
      <el-table-column
        prop="number"
        label="申请人数"
        min-width="100">
      </el-table-column>
      <el-table-column
        prop="teacherName"
        label="负责教师"
        min-width="120">
      </el-table-column>
      <el-table-column
        prop="majorName"
        label="专业"
        min-width="120">
      </el-table-column>
      <el-table-column
        label="申请学生"
        min-width="100">
        <template scope="scope">
          <el-button
            @click="checkNumber(scope.row.graduateProgramID)"
            type="text">
           查看
          </el-button>
        </template>
      </el-table-column>
    </el-table>

    <div class="paging">
      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="page"
        :page-sizes="pageSizes"
        :page-size="pageSize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total">
      </el-pagination>
    </div>
  </div>
</template>
<script>
  export default{
    name: 'classAssociate',
    data(){
      return {
        AssociateForm: {
          majorID: '',
          academicYear: ''
        },
        associateTable: [{
          graduateProgramID: '',
          graduateTitle: '',
          titleSource: '',
          num: '',
          itemCategoryID: '',
          itemCategoryName: '',
          number: '',
          teacherName: '',
          majorName: ''
        }],
        majorData: [],
        page: 1,
        pageSize: 10,
        pageSizes: [10, 20, 30, 40],
        total: 40,
        apiUrl: this.$until.url + '/graduateProgram/getStudentNum',
        initUrl: this.$until.url + '/courseDesign/getMajorDesign'
      }
    },
    mounted: function () {
      this.$nextTick(function () {
        this.init();
      });
    },
    methods: {
      init(){
        this.res();
        this.gerMajorInfo();
      },
      res(){
        this.$http.get(this.apiUrl, {
            params: {
              page: this.page,
              pageSize: this.pageSize
            }
          }
        ).then((res) => {
          this.total = res.body.totalNum.totalNum;
          this.associateTable = res.body.program
        }, (err) => {
          console.log(err);
        })
      },
      gerMajorInfo(){
        this.$http.get(this.initUrl)
          .then((res) => {
            this.majorData = Array.from(res.body);
          }, (err) => {
            console.log(err)
          })
      },
      changeAcademicYear: function (val) {
        this.AssociateForm.academicYear = val;
      },
      search(){
        this.$http.post(this.apiUrl,this.AssociateForm,{
            params: {
              page: this.page,
              pageSize: this.pageSize
            },
          emulateJSON: true
          }
        ).then((res) => {
          this.total = res.body.totalNum.totalNum;
          this.associateTable = res.body.program
        }, (err) => {
          console.log(err);
        })
      },
      checkNumber(graduateProgramID){
        this.$router.push({path: 'AssociateInfo', query: {graduateProgramID: graduateProgramID}})
      },
      handleSizeChange(val) {
        console.log(`每页 ${val} 条`);
      },
      handleCurrentChange(val) {
        this.currentPage = val;
        console.log(`当前页: ${val}`);
      }
    }
  }
</script>
<style>

</style>
